package marchsoft.modules.tiku.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import marchsoft.modules.tiku.entity.ESafeCase;
import marchsoft.base.BasicMapper;
import marchsoft.modules.tiku.entity.dto.ESafeCaseNameDto;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

/**
* <p>
* 安全案例 Mapper 接口
* </p>
*
* @author zsy
* @since 2022-03-29
*/
@Component
public interface ESafeCaseMapper extends BasicMapper<ESafeCase> {
    @Select("SELECT sc.id, sc.title, sc.content, sc.safe_type, sc.pic_path, sc.keywords, sc.tags, " +
            "sc.dislike, sc.page_view, st.name AS safe_name  FROM e_safe_case sc LEFT JOIN e_safe_type st ON sc.safe_type = st.id  ${ew.customSqlSegment} ")
    IPage<ESafeCaseNameDto> queryAllCase(IPage<ESafeCase> page, @Param(Constants.WRAPPER) QueryWrapper<Object> queryWrapper);

    @Select("SELECT * FROM e_safe_case WhERE id = #{id}")
    ESafeCase queryPidCase(Long id);

    @Delete("DELETE FROM e_safe_case WHERE id=#{id}")
    Integer delESafeCase(Long id);

    @Update("UPDATE e_safe_case SET title=#{title}, content=#{content} ,safe_type=#{safeType}, pic_path=#{picPath}, keywords=#{keywords},tags=#{tags}, dislike = #{dislike}, page_view=#{pageView} WHERE id = #{id}")
    Integer updateESafeCase(ESafeCase eSafeCase);

    @Insert("insert into e_safe_case(title,content,safe_type,pic_path,keywords,tags,dislike,page_view,create_by,update_by) values (#{title},#{content},#{safeType},#{picPath},#{keywords},0,0,0,1,1) ")
    Integer addESafeCase(ESafeCase eSafeCase);

}